/*
package com.yunc.base.queue.rabbitmq;

import com.alibaba.fastjson.JSONObject;
import com.yunc.base.netty.WebSocketServerHandler;
import com.yunc.base.utils.R;
import io.netty.channel.Channel;
import io.netty.channel.group.ChannelGroup;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

*/
/**
 * 消费者
 *
 * @author taocongcong
 * @create 2019-10-25 7:47
 *//*

@Component
@Slf4j
public class RabbitMqConsumer {

    @RabbitListener(queues = {"kinson"})
    public void receiver(String msg) {
        System.out.println("kinson_MyReceiver1.............." + msg);
    }

    */
/**
     * rabbitmq中消费者声明一个系统产生的随机队列绑定到这个交换机上，然后往交换机发消息，只要绑定到这个交换机上都能收到消息
     *//*

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(), //注意这里不要定义队列名称,系统会随机产生
            exchange = @Exchange(value = "fanoutExchange",type = ExchangeTypes.FANOUT)
    ))
    public void ackQueueReceiver(String msg) {
        // 带的参数
        JSONObject jsonObject = JSONObject.parseObject(msg);
        String userId = (String) jsonObject.get("userId");
        String title = (String) jsonObject.get("title");
        ChannelGroup channelGroup = WebSocketServerHandler.userChannelMap.get(userId);
        if (channelGroup != null && channelGroup.size() > 0) {
            for (Channel channel : channelGroup) {
                // 发送消息
                String s = "你有消息待查看：" + title;
                channel.writeAndFlush(new TextWebSocketFrame(JSONObject.toJSONString(R.ok().put("type", "1").put("data", s))));
            }
        }
        log.info("指定的Exchange未命名，所有消费者只要绑定都能收到.............." + msg);
    }


    */
/*@RabbitListener(queues = {"ackQueue"})
    public void process(String sendMsg, Channel channel, Message message) {
        System.out.println("AckReceiver  : 收到发送消息 " + sendMsg + ",收到消息时间"
                + LocalDateTime.now(ZoneId.systemDefault()));
        try {
            //告诉服务器收到这条消息已经被当前消费者消费了，可以在队列安全删除，这样后面就不会再重发了，
            //否则消息服务器以为这条消息没处理掉，后续还会再发
            //第二个参数是消息的标识，false只确认当前一个消息收到，true确认所有consumer获得的消息
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
            System.out.println("process success");
        } catch (Exception e) {
            System.out.println("process fail");
            e.printStackTrace();
        }

    }*//*

}
*/
